<?php

namespace app\admin\controller;

use app\admin\controller\Base;
use think\Db;

// 首页
class Home extends Base
{
  // 载入页面
  public function home()
  {


    /**
     * SELECT 
  go.*,
  (SELECT 
    COUNT(cc.task_id) 
  FROM
    v1_task_record AS cc 
  WHERE cc.task_id = go.task_id) AS commentNumber 
FROM
  v1_task go,
  (SELECT 
    COUNT(cc.task_id) 
  FROM
    v1_task_record AS dd 
  WHERE dd.task_id = go.task_id) AS commentNumber2
FROM
  v1_task go 
     */


    // 作业历史
    $record = DB::table('v1_task_record')
      ->where("v1_task_record.student_id", session(USERINFO)['student_id'])
      ->where('v1_task_record.task_record_state', '1')
      ->join('v1_task', 'v1_task_record.task_id=v1_task.task_id')
      ->join('v1_course', 'v1_task.course_id=v1_course.course_id')
      ->order('v1_task_record.task_id desc')->select();
    // 页面赋值
    $this->assign('record', $record);
    // 作业
    $task = DB::table('v1_task')
      ->join('v1_course', 'v1_task.course_id=v1_course.course_id')
      ->order('v1_task.task_create_time desc')->select();
    $this->assign('task', $task);
    // 返回视图页面
    return view("/page/home");
  }
}
